<template>
  <div class="goodItem">
      <img v-lazy="goods.img" alt="" @load="loadImage"  :key="goods.img" @click="goToDetail">
      <div class="goods-info">
        <p>{{goods.title}}</p>
        <span class="price">{{goods.price}}</span>
        <span class="collect" @click="clickCollect" :class="{isCollect:!isCollect}">{{goods.cfav}}</span>
      </div>
    </div>
</template>

<script>
  export default {
    name:"TabGoodsItem",
    props:{
      goods:{
        type:Object,
        default(){
          return {}
        }
      }
    },
    data(){
     return {
       isCollect:true
     }
   },
    methods:{
      goToDetail(){//跳转到商品详情页
        let iid = this.goods.iid
        this.$router.push(`/detail/${iid}`,()=>{})
      },
      clickCollect(){
       if(this.isCollect){
         this.goods.cfav++
         this.isCollect = false
       }else {
         this.goods.cfav--
         this.isCollect = true
       }
     },
     loadImage(){
       this.$bus.$emit('detailImageLoad')
     }
    }
  }
</script>

<style scoped>
  .goodItem {
     width: 48%;
     padding-bottom: 60px;
     position: relative;
     overflow: hidden;
     margin-bottom: 5px;
   }

   .goodItem img {
     width: 100%;
     border-radius: 5px;
   }
   .goods-info {
     /* 给定宽度，对文字省略很重要 */
     width: 100%;
     position: absolute;
     bottom: 0;
     font-size: 15px;
     text-align: center;
   }

   .goods-info p {
     /* 单行 */
     /* white-space: nowrap;
     text-overflow: ellipsis;
     overflow: hidden; */
     /* 多行 */
     text-overflow: -o-ellipsis-lastline;
     overflow: hidden;
     text-overflow: ellipsis;
     display: -webkit-box;
     -webkit-line-clamp: 2;
     line-clamp: 2;
     -webkit-box-orient: vertical;
     
     margin-bottom: 3px;
   }

   .goods-info .price {
    color: var(--color-high-text);
   }

   .goods-info .collect {
    position: relative;
    padding-left: 25px;
    }

  .goods-info .collect::before {
    content: '';
    position: absolute;
    left: 6px;
    top: 0px;
    width: 15px;
    height: 15px;
    background: url("~assets/images/common/collect.svg") 0 0/15px 15px;
  }

  .isCollect {
    color: red;
  }
</style>